package org.yaac.server.egql.evaluator;

import static com.google.common.collect.Sets.newHashSet;

import java.math.BigDecimal;
import java.util.Set;

import org.yaac.server.egql.EntityProperty;
import org.yaac.server.egql.exception.EGQLException;
import org.yaac.server.egql.processor.ProcessData.ProcessDataRecord;



/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class DecimalEvaluator extends Evaluator {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private final BigDecimal value;
	
	/**
	 * @param txtValue
	 */
	public DecimalEvaluator(String txtValue) {
		this.setText(txtValue);
		this.value = new BigDecimal(txtValue);
	}
	
	@Override
	public EvaluationResult evaluate(ProcessDataRecord record) {
		return new EvaluationResult(value).withTitle(this.getText());
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		DecimalEvaluator other = (DecimalEvaluator) obj;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "DecimalEvaluator [value=" + value + "]";
	}

	@Override
	public Set<AggregationEvaluator> aggregationChildren() {
		return newHashSet();
	}
	
	@Override
	public Set<EntityProperty> nonAggregationProperties() {
		return newHashSet();
	}

	@Override
	public void validate() throws EGQLException {		
	}
}
